/**
 * 
 */
package com.yst.metho.web.application.project;

import nextapp.echo2.app.Component;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.Table;
import nextapp.echo2.app.table.TableCellRenderer;

import com.yst.suivi.data.project.Project;
import com.yst.suivi.data.project.ProjectConstante;
import com.yst.suivi.status.StatusUtil;

/**
 * @author perso
 * 
 */
public class ProjectTableCellRenderer implements TableCellRenderer
{
	private static final int TYPE_COLUMN = 3;
	
	private static final int TEAM_COLUMN = 4;

	private static final int ETAT_COLUMN = 2;

	private static final int NOM_COLUMN = 1;

	private static final int CODE_COLUMN = 0;

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
	 *      java.lang.Object, int, int)
	 */
	public Component getTableCellRendererComponent(Table table, Object value, int column, int row)
	{
		Project prj = (Project) value;
		Label label = new Label("");
		if (null != value)
		{
			switch (column)
			{
			case CODE_COLUMN:
				label.setText(prj.getCode());
				break;
			case NOM_COLUMN:
				label.setText(prj.getNom());
				break;
			case ETAT_COLUMN:
				label.setText(StatusUtil.getStatusName(prj.getStatus()));
				break;
			case TEAM_COLUMN:
				if (null != prj.getTeam())
				{
					label.setText(prj.getTeam().getNom());
				}
				break;
			case TYPE_COLUMN:
				if (ProjectConstante.MODE_AT == prj.getTypeProj())
				{
					label.setText("AT");
				}
				else
				{
					label.setText("Forfait");
				}
				break;
			default:
				label.setText("colonne inconnu : " + column);
			}
		}
		else
		{
			label.setText("null");
		}
		if (row % 2 == 0)
		{
			label.setStyleName("ListingView.EvenRowLabel");
		}
		else
		{
			label.setStyleName("ListingView.OddRowLabel");
		}
		return label;
	}

}
